package com.huynv.thetopnews;

import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import android.util.Log;
public class Utils {
	public static String[] allMenuItem = new String[]{"Top Stories","World", "Business", "Technology", "Science", "Entertainment", "Sport", "Health", "Politics","Travel"};
    public static void CopyStream(InputStream is, OutputStream os)
    {
    	/////////////// Neu bai viet cua minh co ich cho ban thi ung ho app cua minh voi nhe
		// https://play.google.com/store/apps/developer?id=GameAppAndroiFree
    	
        final int buffer_size=1024;
        try
        {
            byte[] bytes=new byte[buffer_size];
            for(;;)
            {
              int count=is.read(bytes, 0, buffer_size);
              if(count==-1)
                  break;
              os.write(bytes, 0, count);
            }
        }
        catch(Exception ex){}
    }
    public static String getDomainImage(String domain) {
        if (domain.contains("yahoo")) return Config.domain + "/Images/Icon/yahoo.png";
        if (domain.contains("cnn")) return Config.domain + "/Images/Icon/cnn.png";
        if (domain.contains("nytimes")) return Config.domain + "/Images/Icon/nytimes.png";
        if (domain.contains("reuters")) return Config.domain + "/Images/Icon/reuters.png";
        if (domain.contains("nydailynews")) return Config.domain + "/Images/Icon/nydailynews.png";
        if (domain.contains("usatoday")) return Config.domain + "/Images/Icon/usatoday.png";
        if (domain.contains("latimes")) return Config.domain + "/Images/Icon/latimes.png";
        if (domain.contains("espn")) return Config.domain + "/Images/Icon/espn.png";
        if (domain.contains("huffington")) return Config.domain + "/Images/Icon/huffington.png";
        if (domain.contains("dailymail")) return Config.domain + "/Images/Icon/dailymail.png";
        if (domain.contains("sky")) return Config.domain + "/Images/Icon/sky.png";
        if (domain.contains("guardian")) return Config.domain + "/Images/Icon/guardian.png";
        if (domain.contains("telegraph")) return Config.domain + "/Images/Icon/telegraph.png";
        if (domain.contains("bbc")) return Config.domain + "/Images/Icon/bbc.png";
        if (domain.contains("cnet")) return Config.domain + "/Images/Icon/cnet.png";
        if (domain.contains("techcrunch")) return Config.domain + "/Images/Icon/techcrunch.png";
        if (domain.contains("independent")) return Config.domain + "/Images/Icon/independent.png";
        if (domain.contains("google")) return Config.domain + "/Images/Icon/google.png";
        if (domain.contains("foxnews")) return Config.domain + "/Images/Icon/foxnews.png";
        if (domain.contains("cnbc")) return Config.domain + "/Images/Icon/cnbc.png";
        
        
        return Config.domain+"/Images/logo.png";
    }
    public static String getCatName(String catid){
    	String temp=allMenuItem[Integer.parseInt(catid)];
    	return temp;
    }
    public static Date dateParse(String input) throws java.text.ParseException {

        //NOTE: SimpleDateFormat uses GMT[-+]hh:mm for the TZ which breaks
        //things a bit.  Before we go on we have to repair this.
        SimpleDateFormat df = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssz" );
        
        //this is zero time so we need to add that TZ indicator for 
        if ( input.endsWith( "Z" ) ) {
            input = input.substring( 0, input.length() - 1) + "GMT-00:00";
        } else {
            int inset = 6;
        
            String s0 = input.substring( 0, input.length() - inset );
            String s1 = input.substring( input.length() - inset, input.length() );

            input = s0 + "GMT" + s1;
        }
        Log.e("dateParse=",input);
        return df.parse(input);
        
    }
    public static String removeSC(String html){
    	//html = html.replaceAll("<(.*?)\\>"," ");//Removes all items in brackets
        //html = html.replaceAll("<(.*?)\\\n"," ");//Must be undeneath
        //html = html.replaceFirst("(.*?)\\>", " ");//Removes any connected item to the last bracket
        //html = html.replaceAll("&nbsp;"," ");
        html = html.replaceAll("&amp;"," ");
        return html;
    }
}